

$(document).ready(function(){ 
  getHotCategory();
  getAllCategory();
  getBannerImg();
  getShopDetail();
});

// 获取店铺信息
function getShopDetail(){
  $.ajax({
    url: baseUrl+"/hsent-swfw-user/homePageController/initShopList",
    type:"get",	
    data:"",	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){ 
        var tempData = res.data;
        for(var i = 0 ; i < tempData.length ; i ++){
          for(var j = 0 ; j < tempData[i].shopList.length ; j ++){
            tempData[i].shopList[j].round =  Math.round(tempData[i].shopList[j].shopEvaluateValue);
            tempData[i].shopList[j].cha = 5-tempData[i].shopList[j].round;
          }
        }
        var data={
          data:tempData,
          pirUrl:pirUrl
        }
        var html = template('goods-detail-script', data);
        document.getElementById('shop-detail-box').innerHTML = html;
      }
    },
    error:function(res){

    },
  })
};

// 获取轮播图
function getBannerImg(){
  $.ajax({
    url: baseUrl+"/hsent-swfw-user/homePageController/findHomeBanner",
    type:"get",	
    data:"",	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        var data={
          data:res.data,
          pirUrl:pirUrl
        }
        var html = template('swiper-script', data);
        document.getElementById('swiper-wrapper').innerHTML = html;
        var mySwiper = new Swiper('.swiper-container', {
          swipeToNext: true,
          pagination : '.pagination',
          paginationClickable: true,
          autoplay: 5000, //可选选项，自动滑动
          loop: true, //可选选项，开启循环
      
        })
        $('#prve').click(function(){
          mySwiper.swipePrev();
        })
        $('#next').click(function(){
          mySwiper.swipeNext();
        })
      }
    },
    error:function(res){

    },
  })
};

// 获取全部分类
function getAllCategory(){
  $.ajax({
    url: baseUrl+"/hsent-swfw-user/homePageController/getCategory",
    type:"get",	
    data:"",	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        var data={
          data:res.data,
        }
        var html = template('stabTotal-script', data);
        document.getElementById('stab').innerHTML = html;
        var html2 = template('StabC-script', data);
        document.getElementById('StabC').innerHTML = html2;
      }
    },
    error:function(res){

    },
  })
};

// 获取热门类目
function getHotCategory(){
  $.ajax({
    url: baseUrl+"/hsent-swfw-user/homeCategoryController/findHomeCategory",
    type:"get",	
    data:"",	
    dataType:"json", 
    success:function(res){
      console.log(res);
      if(res.status === 1){
        var data={
          data:res.data,
        }
        var html = template('top-nav-script', data);
        document.getElementById('top-nav').innerHTML = html;
      }
    },
    error:function(res){

    },
  })
};